/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * shoppingCart.java
 *
 * Created on 2011-mar-04, 12:04:12
 */

package imat;

import se.chalmers.ait.dat215.project.IMatDataHandler;
import se.chalmers.ait.dat215.project.ShoppingCart;

/**
 *
 * @author David
 */
public class shoppingCart extends javax.swing.JPanel {

    private ShoppingCart cart = IMatDataHandler.getInstance().getShoppingCart();

    private IMatPresenter presenter = IMatPresenter.getInstance();
    /** Creates new form shoppingCart */
    public shoppingCart() {
        initComponents();
    }

    public shoppingCartList getShoppingCartList () {
        return shoppingCartList1;
    }

    public HeaderPanel2 getMatMallHeaderPanel() {
        return matMallHeaderPanel;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        matMallHeaderPanel = new imat.HeaderPanel2();
        jPanel1 = new javax.swing.JPanel();
        shoppingCartList1 = new imat.shoppingCartList();
        jPanel2 = new javax.swing.JPanel();
        clearCartButton = new javax.swing.JButton();
        keepShoppingButton = new javax.swing.JButton();
        cashInButton = new javax.swing.JButton();

        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(795, 1200));

        matMallHeaderPanel.setName("matMallHeaderPanel"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(795, 1200));

        shoppingCartList1.setName("shoppingCartList1"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imat.IMatApp.class).getContext().getResourceMap(shoppingCart.class);
        clearCartButton.setText(resourceMap.getString("clearCartButton.text")); // NOI18N
        clearCartButton.setToolTipText(resourceMap.getString("clearCartButton.toolTipText")); // NOI18N
        clearCartButton.setName("clearCartButton"); // NOI18N
        clearCartButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearCartButtonActionPerformed(evt);
            }
        });

        keepShoppingButton.setText(resourceMap.getString("keepShoppingButton.text")); // NOI18N
        keepShoppingButton.setToolTipText(resourceMap.getString("keepShoppingButton.toolTipText")); // NOI18N
        keepShoppingButton.setName("keepShoppingButton"); // NOI18N
        keepShoppingButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                keepShoppingButtonActionPerformed(evt);
            }
        });

        cashInButton.setFont(resourceMap.getFont("cashInButton.font")); // NOI18N
        cashInButton.setIcon(resourceMap.getIcon("cashInButton.icon")); // NOI18N
        cashInButton.setText(resourceMap.getString("cashInButton.text")); // NOI18N
        cashInButton.setToolTipText(resourceMap.getString("cashInButton.toolTipText")); // NOI18N
        cashInButton.setName("cashInButton"); // NOI18N
        cashInButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cashInButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(clearCartButton, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                .addComponent(keepShoppingButton, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(55, 55, 55)
                .addComponent(cashInButton, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cashInButton, clearCartButton, keepShoppingButton});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cashInButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(clearCartButton, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(keepShoppingButton, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cashInButton, clearCartButton, keepShoppingButton});

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(shoppingCartList1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 775, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(shoppingCartList1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(72, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(matMallHeaderPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 775, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(matMallHeaderPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 854, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cashInButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cashInButtonActionPerformed
        presenter.displayCategory(IMatView.CASH);
    }//GEN-LAST:event_cashInButtonActionPerformed

    private void clearCartButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearCartButtonActionPerformed
        cart.clear();
        shoppingCartList1.setSum(0);
        shoppingCartList1.getProductPanel().removeAll();
        shoppingCartList1.getProductPanel().revalidate();
        shoppingCartList1.getProductPanel().repaint();

    }//GEN-LAST:event_clearCartButtonActionPerformed

    private void keepShoppingButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keepShoppingButtonActionPerformed
        presenter.displayCategory(IMatView.HOME);
    }//GEN-LAST:event_keepShoppingButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cashInButton;
    private javax.swing.JButton clearCartButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton keepShoppingButton;
    private imat.HeaderPanel2 matMallHeaderPanel;
    private imat.shoppingCartList shoppingCartList1;
    // End of variables declaration//GEN-END:variables

}
